from recruit.models import Enterprise, Recruit
from recruit.serializers.visit_serializer import *
from rest_framework.views import APIView


class VisitEnterpriseView(APIView):
    """增加企业访问次数 接口"""
    queryset = Enterprise.objects.all()
    serializer_class = EnterpriseSimpleSerializer
    lookup_field = 'id'

    def put(self, request, id):
        enterprise = self.queryset.get(id=id)
        enterprise.visits += 1
        enterprise.save()

        return Response({'message': '更新成功', 'success': True})


class VisitRecruitView(APIView):
    """增加职位访问次数 接口"""

    queryset = Recruit.objects.all()
    serializer_class = RecruitSimpleSerializeer
    lookup_field = 'id'

    def put(self, request, id):
        enterprise = self.queryset.get(id=id)
        enterprise.visits += 1
        enterprise.save()

        return Response({'message': '更新成功', 'success': True})
